package cn.webestar.scms.user.api.dto.User;

import cn.webestar.scms.commons.api.LimitBody;
import cn.webestar.scms.user.entity.User;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Date;

@Data
@Schema(description = "UserLimitDTO")
public class UserLimitDTO extends LimitBody {

    @Schema(description = "名称")
    private String name;

    @Schema(description = "性别，0：未知，1：男，2：女")
    private Integer gender;

    @Schema(description = "头像")
    private String avatarUrl;

    @Schema(description = "手机号码")
    private String phoneNum;

    @Schema(description = "用户名")
    private String username;

    @Schema(description = "密码")
    private String pwd;

    @Schema(description = "状态，1：正常")
    private Integer status;

    @Schema(description = "注册时间")
    private Date regtime;

    @Schema(description = "最后登录时间")
    private Date lastLoginTime;

    @Schema(description = "创建人")
    private Long creator;

    @Schema(description = "更新人")
    private Long updater;

    @Schema(description = "删除人")
    private Long deleter;

    @Schema(description = "创建时间")
    private Date createTime;

    @Schema(description = "更新时间")
    private Date updateTime;

    @Schema(description = "删除时间")
    private Date deleteTime;

    @Schema(description = "是否已删除")
    private Boolean isDeleted;

    @Override
    public LambdaQueryWrapper<User> toQueryWapper() {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(name)) {
            queryWrapper.eq(User::getName, name);
        }
        if (gender!=null) {
            queryWrapper.eq(User::getGender, gender);
        }
        if (StringUtils.hasText(avatarUrl)) {
            queryWrapper.eq(User::getAvatarUrl, avatarUrl);
        }
        if (StringUtils.hasText(phoneNum)) {
            queryWrapper.eq(User::getPhoneNum, phoneNum);
        }
        if (StringUtils.hasText(username)) {
            queryWrapper.eq(User::getUsername, username);
        }
        if (StringUtils.hasText(pwd)) {
            queryWrapper.eq(User::getPwd, pwd);
        }
        if (status!=null) {
            queryWrapper.eq(User::getStatus, status);
        }
        if (regtime!=null) {
            queryWrapper.eq(User::getRegtime, regtime);
        }
        if (lastLoginTime!=null) {
            queryWrapper.eq(User::getLastLoginTime, lastLoginTime);
        }
        if (creator!=null) {
            queryWrapper.eq(User::getCreator, creator);
        }
        if (updater!=null) {
            queryWrapper.eq(User::getUpdater, updater);
        }
        if (deleter!=null) {
            queryWrapper.eq(User::getDeleter, deleter);
        }
        if (createTime!=null) {
            queryWrapper.eq(User::getCreateTime, createTime);
        }
        if (updateTime!=null) {
            queryWrapper.eq(User::getUpdateTime, updateTime);
        }
        if (deleteTime!=null) {
            queryWrapper.eq(User::getDeleteTime, deleteTime);
        }
        if (isDeleted!=null) {
            queryWrapper.eq(User::getIsDeleted, isDeleted);
        }
        queryWrapper.last("LIMIT " + this.getOffset() + "," + this.getLimit());
        return queryWrapper;
    }
    
}
